﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Maticsoft.Web
{
    public partial class NewsList : System.Web.UI.Page
    {
        int cid;
        protected void Page_Load(object sender, EventArgs e)
        {
            int.TryParse(Request.QueryString["cid"], out cid);
            if (!IsPostBack)
            {
                GetData();
                GetNav(cid);
            }
        }

        protected void GetData()
        {
            if (cid > 0)
            {
                BLL.Channel chaBLL = new BLL.Channel();
                Model.Channel chaModel = chaBLL.GetModel(cid);
                Title = chaModel.ChannelName;
            }
        }

        protected void BindList()
        {
            BLL.News newsBLL = new BLL.News();
            int count = newsBLL.GetRecordCount("ChannelId=" + cid + " and IsActive=1");
            AspNetPager1.RecordCount = count;
            DataSet ds = newsBLL.GetListByPage("ChannelId=" + cid + " and IsActive=1", "CreateTime desc", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }

        protected string nav = string.Empty;
        protected string GetNav(int id)
        {
            string curr = string.Empty;
            BLL.Channel catBLL = new BLL.Channel();
            Model.Channel catModel = catBLL.GetModel(id);
            curr = "<span> > </span><a href=\"javascript:;\" class=\"fs-14\">" + catModel.ChannelName + " </a>";
            if (catModel.ParentId != 0)
            {
                nav = GetNav((int)catModel.ParentId) + curr;
            }
            else
            {
                nav = nav + curr;
            }

            return nav;
        }

        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            BindList();
        }
    }
}